package com.example.yang.yixin.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.yang.yixin.FragmentManager.Fragment_All;
import com.example.yang.yixin.FragmentManager.Fragment_Earlyorlate;
import com.example.yang.yixin.FragmentManager.Fragment_person;
import com.example.yang.yixin.FragmentManager.Fragment_phonecontrol;
import com.example.yang.yixin.R;
public class QuestionActivity extends AppCompatActivity{
     ImageView mIv_backchange;
     ImageView mIv_mechange;
     SharedPreferences pref;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_question);
        Fragment_person Fragment_person=new Fragment_person();
        Bundle bundle=new Bundle();
        bundle.putString("one",getIntent().getStringExtra("one"));
        bundle.putString("two",getIntent().getStringExtra("two"));
        bundle.putString("three",getIntent().getStringExtra("three"));
        Fragment_person.setArguments(bundle);
        getSupportFragmentManager().beginTransaction().add(R.id.Fr_container,Fragment_person).commit();
        pref=getSharedPreferences("user",MODE_PRIVATE);

        mIv_backchange=findViewById(R.id.iv_backchange);
        mIv_mechange=findViewById(R.id.iv_mechange);
        registerForContextMenu( mIv_mechange);
        mIv_mechange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openContextMenu(v);
            }
        });
        mIv_backchange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(QuestionActivity.this,PersonActivity.class);
                startActivity(intent);
            }
        });


    }


    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.add(1, 1, 1, "个人出勤");
        menu.add(1, 2, 2, "总体出勤");
        menu.add(1, 3, 3, "迟到早退");
        menu.add(1, 4, 4, "锁屏统计");

    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
        Fragment_All fragment_all=new Fragment_All();
        Fragment_person fragment_person=new Fragment_person();
        Fragment_Earlyorlate fragment_earlyorlate=new Fragment_Earlyorlate();
        Fragment_phonecontrol fragment_phonecontrol=new Fragment_phonecontrol();
        String bkpassword=pref.getString("bkpassword",null);
        switch(item.getItemId()){
            case 1:

                Bundle bundle=new Bundle();
                bundle.putString("bkpassword",bkpassword);
                fragment_all.setArguments(bundle);
                fragmentTransaction.replace(R.id.Fr_container,fragment_all);
                fragmentTransaction.commit();
                break;
            case 2:
                Bundle bundle1=new Bundle();
                bundle1.putString("one",getIntent().getStringExtra("one"));
                bundle1.putString("two",getIntent().getStringExtra("two"));
                bundle1.putString("three",getIntent().getStringExtra("three"));
                fragment_person.setArguments(bundle1);
                fragmentTransaction.replace(R.id.Fr_container,fragment_person);
                fragmentTransaction.commit();
                break;
            case 3:
                Bundle bundle2=new Bundle();
                bundle2.putString("bkpassword",bkpassword);
                bundle2.putString("one",getIntent().getStringExtra("mostearly"));
                bundle2.putString("two",getIntent().getStringExtra("onetothree"));
                bundle2.putString("three",getIntent().getStringExtra("other"));
                fragment_earlyorlate.setArguments(bundle2);
                fragmentTransaction.replace(R.id.Fr_container,fragment_earlyorlate);
                fragmentTransaction.commit();
                break;
            case 4:
               Bundle bundle3=new Bundle();
                bundle3.putString("bkpassword",bkpassword);
                bundle3.putString("controlmost",getIntent().getStringExtra("controlmost"));
                bundle3.putString("controlonetothree",getIntent().getStringExtra("controlonetothree"));
                bundle3.putString("controlother",getIntent().getStringExtra("controlother"));
                fragment_phonecontrol.setArguments(bundle3);
                fragmentTransaction.replace(R.id.Fr_container,fragment_phonecontrol);
                fragmentTransaction.commit();
                break;


        }
        return true;
    }

}
